using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using Flynn.Core;
using FlynnGui.Infrastructure;

namespace FlynnGui.ViewModels
{
	public class UpdateViewModel : INotifyPropertyChanged
	{
		private string _version;
		private string _author;
		private string _createdDate;
		private string _desription;
		private readonly DelegateCommand _editUpdateCommand;

		public UpdateViewModel(Update update)
		{
			Version = update.Version;
			Author = update.Author;
			CreatedDate = update.CreatedDate.HasValue ? update.CreatedDate.Value.ToShortDateString() : string.Empty;
			Description = update.Description;
			SqlStatements = new ObservableCollection<string>(new List<string>(update.SqlStatements));

			_editUpdateCommand = new DelegateCommand(EditUpdateCommandHandler);
		}

		public string Version
		{
			get { return _version; }
			set
			{
				_version = value;
				NotifyPropertyChanged("Version");
			}
		}

		public string Author
		{
			get { return _author; }
			set
			{
				_author = value;
				NotifyPropertyChanged("Author");
			}
		}

		public string CreatedDate
		{
			get { return _createdDate; }
			set
			{
				_createdDate = value;
				NotifyPropertyChanged("CreatedDate");
			}
		}

		public string Description
		{
			get { return _desription; }
			set
			{
				_desription = value;
				NotifyPropertyChanged("Description");
			}
		}

		public ObservableCollection<string> SqlStatements { get; private set; }

		public DelegateCommand EditUpdateCommand
		{
			get { return _editUpdateCommand; }
		}

		public event PropertyChangedEventHandler PropertyChanged;

		private void EditUpdateCommandHandler(object sender, DelegateCommandEventArgs e)
		{
			MessageBox.Show("slkdjhf");
		}

		private void NotifyPropertyChanged(string info)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(info));
		}
	}
}